<?php

namespace pmvc\mvc\ioc;

use pmvc\util\XMLUtil;

use pmvc\ioc\xml\ParseContext;
use pmvc\ioc\PropertyDescriptor;
use pmvc\ioc\ObjectDescriptor;
use pmvc\ioc\xml\Extension;

use DOMElement;

/**
 * An {@link Extension} for view only controllers.
 *
 */
class ViewOnlyControllerExtension
	implements Extension {

	/**
	 * {@inheritDoc}
	 */
	public function process(DOMElement $element, ParseContext $pc) {

		// get the variables
		$name 		= XMLUtil::getAttributeValue($element, "name");
		$id 		= XMLUtil::getAttributeValue($element, "id");
		$viewName 	= XMLUtil::getAttributeValue($element, "viewName");

		// create id if needed
		if (!isset($id)) {
			$id = uniqid('', true) . '#ViewOnlyControllerExtension';
		}

		// create and add descriptor
		$objDescriptor = new ObjectDescriptor($id, 'pmvc\mvc\controller\ViewOnlyController', $name);
		$objDescriptor->properties []= new PropertyDescriptor("viewName", $viewName, PropertyDescriptor::TYPE_STRING);
		$pc->getObjectFactory()->addObjectDescriptor($objDescriptor);
	}
	
}


?>